﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using AvalonDock.Layout;
using AvalonDock.Layout.Serialization;
using Microsoft.Win32;
using Zero.UControl.Base;
using Zero.UControl.Demo.Helper;
using Zero.UControl.Base.Models;
using Zero.UControl.Component;
using Zero.UControl.Component.Common;
using Zero.UControl.Component.MsgBox;
using Zero.UControl.Component.Notification;
using Zero.UControl.Demo.Views.LoadingDemo;
using Zero.UControl.Demo.Views.ScreenCut;
using Zero.UControl.Base.Helper;

namespace Zero.UControl.Demo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged, IDisposable
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
            Closed += MainWindow_Closed;
            List<string> whiteList = new List<string>() { "prop" };
            List<LayoutAnchorable> items = dockingManager.Layout.Descendents().OfType<LayoutAnchorable>().ToList();
            for (int i = 0; i < items.Count; i++)
            {
                //if (whiteList.Contains(items[i].ContentId))
                //{
                //    // 设置停靠 需要配合 DockMinWidth 
                //    LayoutAnchorablePane? pane = items[i].Parent as LayoutAnchorablePane;
                //    if (pane != null)
                //        pane.DockMinWidth = 240.0;
                //    items[i].Show();
                //    continue;
                //}
                // 设置隐藏
                items[i].ToggleAutoHide();
            }

            RaderDatas.Add(new RaderSeriesModel() { Header = "标题1", Value = 20 });
            RaderDatas.Add(new RaderSeriesModel() { Header = "标题2", Value = 70 });
            RaderDatas.Add(new RaderSeriesModel() { Header = "标题3", Value = 40 });
            RaderDatas.Add(new RaderSeriesModel() { Header = "标题4", Value = 80 });
            RaderDatas.Add(new RaderSeriesModel() { Header = "标题5", Value = 30 });
            RaderDatas.Add(new RaderSeriesModel() { Header = "标题6", Value = 90 });

            LoadingMenus.Add(new TabNavItem() { NavName = "LoadingDemo", Element = new LoadingDemo() });
            LoadingMenus.Add(new TabNavItem() { NavName = "RingLoading", Element = new RingLoading() });
            LoadingMenus.Add(new TabNavItem() { NavName = "RollLoading", Element = new RollLoading() });
            LoadingMenus.Add(new TabNavItem() { NavName = "ProgressLoading", Element = new ProgressLoading() });
            LoadingMenus.Add(new TabNavItem() { NavName = "ProgressRing", Element = new ProgressRing() });
            LoadingMenus.Add(new TabNavItem() { NavName = "DotLoading", Element = new DotLoading() });

            TimelineItems = CreateTimelineItems();
            SearchParam = new ObservableCollection<DynamicQueryItem>()
            {
                new DynamicQueryItem(){ Title = "项目名称", OpType = OperateType.Like, Field = "ProjectName" },
                new DynamicQueryItem(){ Title = "企业名称", OpType = OperateType.Like, Field = "CompanyName" },
                new DynamicQueryItem(){ Title = "项目地址", OpType = OperateType.Like, Field = "ProjectAddress" }
            };
            TreeViewInit();
            CascaderInit();
            SuggestionsInit();
            StepListInit();

            MyCalendar.CurrentDate = DateTime.Today;
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        private Random random = new Random();
        private CancellationTokenSource cts1 = new CancellationTokenSource();
        private CancellationTokenSource cts2 = new CancellationTokenSource();
        private Task task1;     // 表盘更新线程
        private Task task2;     // 电池充电进度更新线程

        #region 属性
        private double speed = 2000;

        public double Speed
        {
            get { return speed; }
            set
            {
                speed = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Speed)));
            }
        }

        private double meterVal = 20;

        public double MeterVal
        {
            get { return meterVal; }
            set
            {
                meterVal = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MeterVal)));
            }
        }

        private int proValue = 0;

        public int ProValue
        {
            get { return proValue; }
            set
            {
                proValue = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ProValue)));
            }
        }

        private string badgeTitle = "0";

        public string BadgeTitle
        {
            get { return badgeTitle; }
            set
            {
                badgeTitle = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BadgeTitle)));
            }
        }

        private string passwd;

        public string Passwd
        {
            get { return passwd; }
            set
            {
                passwd = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Passwd)));
            }
        }

        private int currentStep = 1;

        public int CurrentStep
        {
            get { return currentStep; }
            set 
            {
                currentStep = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentStep)));
            }
        }

        private bool leftDrawerShow = false;

        public bool LeftDrawerShow
        {
            get { return leftDrawerShow; }
            set 
            {
                leftDrawerShow = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LeftDrawerShow)));
            }
        }

        private bool topDrawerShow = false;

        public bool TopDrawerShow
        {
            get { return topDrawerShow; }
            set
            {
                topDrawerShow = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TopDrawerShow)));
            }
        }

        private bool rightDrawerShow = false;

        public bool RightDrawerShow
        {
            get { return rightDrawerShow; }
            set
            {
                rightDrawerShow = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(RightDrawerShow)));
            }
        }

        private bool bottomDrawerShow = false;

        public bool BottomDrawerShow
        {
            get { return bottomDrawerShow; }
            set
            {
                bottomDrawerShow = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BottomDrawerShow)));
            }
        }

        private bool isShowDialog;

        public bool IsShowDialog
        {
            get { return isShowDialog; }
            set 
            {
                isShowDialog = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsShowDialog)));
            }
        }

        private string queryStr;

        public string QueryStr
        {
            get { return queryStr; }
            set 
            { 
                queryStr = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(QueryStr)));
            }
        }


        public ObservableCollection<RaderSeriesModel> RaderDatas { get; set; } = new ObservableCollection<RaderSeriesModel>();
        public ObservableCollection<TabNavItem> LoadingMenus { get; set; } = new ObservableCollection<TabNavItem>();
        public ObservableCollection<TimelineItem> TimelineItems { get; set; }
        public ObservableCollection<DynamicQueryItem> SearchParam { get; set; }
        public ObservableCollection<NodeItem> RootNodes { get; set; }

        public ObservableCollection<CascaderItem> RootItems { get; set; }
        public ObservableCollection<CascaderItem> SelectedItems { get; set; } = new ObservableCollection<CascaderItem>();
        public ObservableCollection<string> Suggestions { get; set; }
        public ObservableCollection<StepBarItem> StepList { get; set; }
        #endregion

        #region 事件
        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.K && Keyboard.Modifiers == ModifierKeys.Control)
            {
                Win32Helper.GetCursorPos(out var point);
                Debug.WriteLine($"point: {point.X},{point.Y}");
                Win32Helper.DoubleClick(point);
            }
            else if (e.Key == Key.F1)
            {
                ScreenCutView screenCutView = new ScreenCutView();
                screenCutView.Show();
            }
        }

        /// <summary>
        /// 表盘页面激活
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LayoutDocument_IsActiveChanged(object sender, EventArgs e)
        {
            if (sender is LayoutDocument document)
            {
                if (document.IsActive)
                {
                    cts1 = new CancellationTokenSource();
                    task1 = Task.Run(async () =>
                    {
                        while (!cts1.IsCancellationRequested)
                        {
                            MeterVal = random.Next(0, 100);
                            await Task.Delay(1000);
                        }
                    });
                }
                else
                {
                    cts1.Cancel();
                }
            }
        }

        /// <summary>
        /// 充电页面激活
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LayoutDocument_IsActiveChanged2(object sender, EventArgs e)
        {
            if (sender is LayoutDocument document)
            {
                if (document.IsActive)
                {
                    cts2 = new CancellationTokenSource();
                    task2 = Task.Run(async () =>
                    {
                        while (!cts2.IsCancellationRequested)
                        {
                            ProValue++;
                            if (ProValue > 100)
                                ProValue = 0;
                            await Task.Delay(1000);
                        }
                    });
                }
                else
                {
                    cts2.Cancel();
                }
            }
        }

        /// <summary>
        /// 树节点页面激活
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeViewLayoutDocument_IsActiveChanged(object sender, EventArgs e)
        {
            return;
            TreeViewInit();
        }
        #endregion

        #region 重置界面布局
        private string _initialLayout;
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            XmlLayoutSerializer serializer = new XmlLayoutSerializer(dockingManager);
            using (var writer = new StringWriter())
            {
                serializer.Serialize(writer);
                _initialLayout = writer.ToString();
            }
        }

        private void ResetLayout(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(_initialLayout))
            {
                var serializer = new XmlLayoutSerializer(dockingManager);
                using (var reader = new StringReader(_initialLayout))
                {
                    serializer.Deserialize(reader); // 恢复到初始状态
                }
            }
        }

        #endregion

        #region 消息提示
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageManage.Success("点击了测试", "MainMessageToken");
        }
        #endregion

        #region 消息通知
        private NotificationHost _host;
        private void Notify_Button_Click(object sender, RoutedEventArgs e)
        {
            if (_host == null)
            {
                _host = new NotificationHost();
            }
            Label lb = new Label()
            {
                Foreground = new SolidColorBrush(Colors.Black),
                Content = "Hello WPF"
            };
            var border = new Border()
            {
                Background = new SolidColorBrush(Colors.AliceBlue),
                CornerRadius = new CornerRadius(5),
                Margin = new Thickness(0, 2, 0, 0),
                Child = lb
            };

            _host.ShowNotification("新消息", "您有一条新提醒。", border);
        }
        #endregion

        #region 截图
        private void RegionCropBtnClick(object sender, RoutedEventArgs e)
        {
            ScreenCutView screenCutView = new ScreenCutView();
            screenCutView.ShowDialog();
        }

        private void FullScreenCropBtnClick(object sender, RoutedEventArgs e)
        {
            var view = new ScreenCutView();
            view.CreateFullScreenBitmap();
            MessageManage.Success("全屏截图成功", "MainMessageToken2");
        }
        #endregion

        #region 语音处理

        private void ShowVoicesBtnClick(object sender, RoutedEventArgs e)
        {
            List<string> voices = SpeechHelper.GetInstalledVoices().ToList();
            vsList.ItemsSource = voices;
        }

        private void SpeekTextBtnClick(object sender, RoutedEventArgs e)
        {
            string text = InputText.Text.Trim();
            SpeechHelper.SpeakAsync(text);
        }
        #endregion

        #region OCR识别

        BitmapSource _bitmapSource;


        private void CutRecRegion(object sender, RoutedEventArgs e)
        {
            ScreenCutView screenCutView = new ScreenCutView();
            screenCutView.OperateCompleted += ScreenCutView_OperateCompleted;
            screenCutView.Show();
        }

        private void ScreenCutView_OperateCompleted(object? sender, BitmapSource bitmapSource)
        {
            _bitmapSource = bitmapSource;
            recognizeImg.Source = bitmapSource;
        }

        private async void DoRecoginze(object sender, RoutedEventArgs e)
        {
            if (_bitmapSource != null)
            {
                loading.State = LoadingState.Loading;
                await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
                await Task.Run(() =>
                {
                    PaddleOCRSharp.OCRResult result = OCRHelper.Recognize(_bitmapSource);
                    recognizeText.Dispatcher.Invoke(() =>
                    {
                        recognizeText.Text = string.Join(" ", result.TextBlocks.Select(b => b.Text));
                    });
                });
                
                loading.State = LoadingState.UnLoading;
            }
            else
            {
                MessageBox.Show("当前未截取到有效图片");
            }
        }

        private void CopyContent(object sender, RoutedEventArgs e)
        {
            Clipboard.SetText(recognizeText.Text);
        }

        private void ClearContent(object sender, RoutedEventArgs e)
        {
            recognizeText.Text = string.Empty;
        }
        #endregion

        #region Image 转换
        private void SelectFile_Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Image file | *.jpg;*.png;*.jpeg;";
            bool? flag = dialog.ShowDialog();
            if (flag.HasValue && flag.Value == false)
                return;
            imgPath.Text = dialog.FileName;
            imgPath2.Text = dialog.FileName;
        }

        private void Convert_Button_Click(object sender, RoutedEventArgs e)
        {
            string filePath = imgPath.Text.Trim();
            if (string.IsNullOrWhiteSpace(filePath)) return;

            string dir = AppDomain.CurrentDomain.BaseDirectory + "Icon";
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string destPath = $"{dir}{Path.DirectorySeparatorChar}target.ico";
            ImageHelper.ConvertToIcon(filePath, destPath);
            System.Drawing.Image image = System.Drawing.Image.FromFile(destPath);
            IconImg.Source = ImageHelper.ImageToBitmapSource(image);
        }

        private void Convert_Png_Button_Click(object sender, RoutedEventArgs e)
        {
            string filePath = imgPath2.Text.Trim();
            if (string.IsNullOrWhiteSpace(filePath)) return;

            string dir = AppDomain.CurrentDomain.BaseDirectory + "Png";
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string destPath = $"{dir}{Path.DirectorySeparatorChar}target.png";
            try
            {
                ImageHelper.ConvertToPng(filePath, destPath);
                MessageBox.Show("转换成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"转换失败，{ex.Message}");
            }

        }

        #endregion

        #region 消息提示框
        private void Info_Button_Click(object sender, RoutedEventArgs e)
        {
            MsgBoxManager.Info("欢迎使用可视化编辑器组件，请从左侧工具栏中选择一个图形添加到画布，然后使用鼠标进行操作。");
        }

        private void Warn_Button_Click(object sender, RoutedEventArgs e)
        {
            MsgBoxManager.Warn("欢迎使用可视化编辑器组件，请从左侧工具栏中选择一个图形添加到画布，然后使用鼠标进行操作。");
        }

        private void Error_Button_Click(object sender, RoutedEventArgs e)
        {
            MsgBoxManager.Error("欢迎使用可视化编辑器组件，请从左侧工具栏中选择一个图形添加到画布，然后使用鼠标进行操作。");
        }

        #endregion

        #region 时间线
        private ObservableCollection<TimelineItem> CreateTimelineItems()
        {
            var rawItems = new List<TimelineItem>
            {
                new TimelineItem
                {
                    DateGroup = "2025-07-07",
                    User = "在路上",
                    AvatarBackground = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Avatars/Bird.png",
                    Title = "Star 了仓库",
                    Description = "15 小时前",
                    Link = "Zero/自定义通信库\n包括Modbus串口、网口；西门子S7，三菱MC，欧姆龙Fins串口、FinsTcp，CIP，以及SecsGem的通信协议封装"
                },
                new TimelineItem
                {
                    DateGroup = "2025-07-04",
                    User = "Zero",
                    AvatarBackground = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Avatars/katong2.png",
                    Title = "推送到了分支",
                    Description = "Zero/自定义WPF控件库的 master 分支",
                    Link = "db9adcf  分页插件待完善"
                },
                new TimelineItem
                {
                    DateGroup = "2025-07-04",
                    User = "wenxi",
                    AvatarBackground = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Avatars/katong3.png",
                    Title = "Star 了仓库",
                    Description = "4 天前",
                    Link = "Zero/自定义通信库\n包括Modbus串口、网口；西门子S7，三菱MC，欧姆龙Fins串口、FinsTcp，CIP，以及SecsGem的通信协议封装"
                },
                new TimelineItem
                {
                    DateGroup = "2025-07-03",
                    User = "Zero",
                    AvatarBackground = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Avatars/Pikachu.png",
                    Title = "发布新版本",
                    Description = "v1.2.1 发布，修复了协议连接的问题",
                    Link = ""
                },
                new TimelineItem
                {
                    DateGroup = "2025-07-02",
                    User = "Zero",
                    AvatarBackground = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Avatars/katong2.png",
                    Title = "发布新版本",
                    Description = "v1.2.1 发布，修复了协议连接的问题",
                    Link = ""
                },
                new TimelineItem
                {
                    DateGroup = "2025-07-01",
                    User = "Zero",
                    AvatarBackground = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Avatars/katong3.png",
                    Title = "推送到了分支",
                    Description = "Zero/自定义WPF控件库的 master 分支",
                    Link = "db9adcf  分页插件待完善"
                },
                new TimelineItem
                {
                    DateGroup = "2025-06-30",
                    User = "在路上",
                    AvatarBackground = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Avatars/Bird.png",
                    Title = "Star 了仓库",
                    Description = "15 小时前",
                    Link = "Zero/自定义通信库\n包括Modbus串口、网口；西门子S7，三菱MC，欧姆龙Fins串口、FinsTcp，CIP，以及SecsGem的通信协议封装"
                },
                new TimelineItem
                {
                    DateGroup = "2025-06-29",
                    User = "Zero",
                    AvatarBackground = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Avatars/Pikachu.png",
                    Title = "发布新版本",
                    Description = "v1.2.1 发布，修复了协议连接的问题",
                    Link = ""
                },
            };

            // 设置每组第一条 ShowDateGroup = true
            return new ObservableCollection<TimelineItem>(
                rawItems.GroupBy(i => i.DateGroup)
                        .SelectMany(g =>
                        {
                            var groupItems = g.ToList();
                            groupItems[0].ShowDateGroup = true;
                            return groupItems;
                        }));
        }
        #endregion

        #region 标记

        private void Badge_Button_Click(object sender, RoutedEventArgs e)
        {
            BadgeTitle = BadgeTitle == "0" ? "1" : "0";
        }
        #endregion

        #region 对象销毁
        private void MainWindow_Closed(object? sender, EventArgs e)
        {
            Dispose();
        }

        public void Dispose()
        {
            cts1.Cancel();
            cts2.Cancel();
            TaskDispose(task1);
            TaskDispose(task2);
        }

        private void TaskDispose(Task task)
        {
            if (task != null && (task.IsCompleted || task.IsCanceled || task.IsFaulted))
            {
                task.Dispose();
            }
        }
        #endregion

        #region 树节点初始化
        private void TreeViewInit()
        {
            RootNodes?.Clear();
            RootNodes = new ObservableCollection<NodeItem>
            {
                  new NodeItem
                  {
                        Name = "内置节点",
                        NodeType = NodeType.Parent,
                        Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/Lib.png",
                        Children = {
                              new NodeItem
                                {
                                Name = "函数节点",
                                NodeType = NodeType.Parent,
                                Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/Folder.png",
                                Children = {
                                    new NodeItem {
                                        Name = "运算函数",
                                        NodeType = NodeType.Parent,
                                        Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/Folder.png",
                                        Children =
                                        {
                                             new NodeItem { Name = "关系运算",NodeType = NodeType.Child, Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" }
                                        }
                                    },
                                    new NodeItem {
                                        Name = "执行控制",
                                        NodeType = NodeType.Parent,
                                        Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/Folder.png",
                                        Children =
                                        {
                                             new NodeItem { Name = "多线程执行", NodeType = NodeType.Child, Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                             new NodeItem { Name = "延迟执行", NodeType = NodeType.Child, Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                             new NodeItem { Name = "暂停执行", NodeType = NodeType.Child, Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                        }
                                    },
                                    new NodeItem
                                    {
                                        Name = "转换器",
                                        NodeType = NodeType.Parent,
                                        Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/Folder.png",
                                        Children = {
                                            new NodeItem { Name = "多线程执行", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                            new NodeItem { Name = "延迟执行", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" }
                                        }
                                    }
                                }
                            },
                              new NodeItem
                              {
                                  Name = "流程控制节点",
                                  NodeType = NodeType.Parent,
                                  Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/Folder.png",
                                  Children =
                                  {
                                      new NodeItem { Name = "计数循环", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                      new NodeItem { Name = "判断", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                      new NodeItem { Name = "条件循环", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                      new NodeItem { Name = "选择执行", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                  }
                              },
                              new NodeItem
                              {
                                  Name = "驱动节点",
                                  NodeType = NodeType.Parent,
                                  Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/Folder.png",
                                  Children =
                                  {
                                      new NodeItem { Name = "定时驱动器",NodeType = NodeType.Child, Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                      new NodeItem { Name = "帧驱动器", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" }
                                  }
                              },
                              new NodeItem
                              {
                                  Name = "事件节点",
                                  NodeType = NodeType.Parent,
                                  Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/Folder.png",
                                  Children =
                                  {
                                      new NodeItem { Name = "按键",NodeType = NodeType.Child, Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" }
                                  }
                              },
                              new NodeItem
                              {
                                  Name = "数据节点",
                                  NodeType = NodeType.Parent,
                                  Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/Folder.png",
                                  Children =
                                  {
                                      new NodeItem { Name = "小数", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                      new NodeItem { Name = "复数", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" },
                                      new NodeItem { Name = "字符串", NodeType = NodeType.Child,Icon = "pack://application:,,,/Zero.UControl.Assets;component/Imgs/Trees/NodePreset.png" }
                                  }
                              }
                        }
                  }
            };
        }
        #endregion

        #region 级联选择节点初始化
        private void CascaderInit()
        {
            RootItems = new ObservableCollection<CascaderItem>
            {
                new CascaderItem
                {
                    Label = "指南",
                    Value = "guide",
                    Children = new ObservableCollection<CascaderItem>
                    {
                        new CascaderItem
                        {
                            Label = "设计原则",
                            Value = "design",
                            Children = new ObservableCollection<CascaderItem>
                            {
                                new CascaderItem { Label = "一致", Value = "consistency" },
                                new CascaderItem { Label = "反馈", Value = "feedback" },
                                new CascaderItem { Label = "可控", Value = "controllable" }
                            }
                        },
                        new CascaderItem
                        {
                            Label = "导航",
                            Value = "navigation"
                        }
                    }
                },
                new CascaderItem
                {
                    Label = "组件",
                    Value = "components",
                    Children = new ObservableCollection<CascaderItem>
                    {
                        new CascaderItem {
                            Label = "表单",
                            Value = "form",
                            Children = new ObservableCollection<CascaderItem>()
                            {
                                new CascaderItem
                                {
                                     Label = "表单1",
                                     Value = "form1",
                                },
                                new CascaderItem
                                {
                                     Label = "表单2",
                                     Value = "form2",
                                }
                            }
                        },
                        new CascaderItem {
                            Label = "表格",
                            Value = "table",
                            Children = new ObservableCollection<CascaderItem>()
                            {
                                new CascaderItem
                                {
                                     Label = "表格1",
                                     Value = "table1",
                                },
                                new CascaderItem
                                {
                                     Label = "表格2",
                                     Value = "table2",
                                }
                            }
                        }
                    }
                }
            };

            // 建立父级引用（便于 FullPath 路径显示）
            SetParentRecursive(RootItems, null);
        }

        private void SetParentRecursive(ObservableCollection<CascaderItem> items, CascaderItem parent)
        {
            foreach (var item in items)
            {
                item.Parent = parent;
                if (item.Children != null && item.Children.Count > 0)
                    SetParentRecursive(item.Children, item);
            }
        }
        #endregion

        #region 提示词初始化
        private void SuggestionsInit()
        {
            Suggestions = new ObservableCollection<string>
            {
                "Apple",
                "Apricot",
                "Avocado",
                "Banana",
                "Blueberry",
                "Blackberry",
                "Cherry",
                "Coconut",
                "Grape",
                "Guava",
                "Mango",
                "Melon",
                "Orange",
                "Peach",
                "Pear",
                "Pineapple",
                "Strawberry",
                "Watermelon"
            };
        }
        #endregion

        #region 步骤条初始化
        private void StepListInit()
        {
            StepList = new ObservableCollection<StepBarItem>()
            {
                new StepBarItem(){ Order = 1, Title = "步骤一",Description = "公钥获取" },
                new StepBarItem(){ Order = 2, Title = "步骤二",Description = "认证登录" },
                new StepBarItem(){ Order = 3, Title = "步骤三",Description = "权限验证" },
                new StepBarItem(){ Order = 4, Title = "步骤四",Description = "获取菜单项" },
                new StepBarItem(){ Order = 5, Title = "步骤五",Description = "加载统计数据" },
                new StepBarItem(){ Order = 6, Title = "步骤六",Description = "获取通知消息" },
            };
        }

        private void Prev_Button_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentStep == 1) return;
            CurrentStep--;
        }

        private void Next_Button_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentStep == StepList.Count) return;
            CurrentStep++;
        }

        #endregion

        #region 抽屉展示隐藏
        private void Left_Drawer_Button_Click(object sender, RoutedEventArgs e)
        {
            LeftDrawerShow = !LeftDrawerShow;
        }

        private void Top_Drawer_Button_Click(object sender, RoutedEventArgs e)
        {
            TopDrawerShow = !TopDrawerShow;
        }

        private void Right_Drawer_Button_Click(object sender, RoutedEventArgs e)
        {
            RightDrawerShow = !RightDrawerShow;
        }

        private void Bottom_Drawer_Button_Click(object sender, RoutedEventArgs e)
        {
            BottomDrawerShow = !BottomDrawerShow;
        }
        #endregion

        #region Dialog弹窗
        private void ShowDialog_Button_Click(object sender, RoutedEventArgs e)
        {
            IsShowDialog = !IsShowDialog;
        }
        #endregion
    }
}